# -*- coding: utf-8 -*-
from itchat.content import *
import requests
import json
import itchat

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
	appkey ="e5ccc9c7c8834ec3b08940e290ff1559"
	info=msg['Text']
	print(info)
	url="http://www.tuling123.com/openapi/api?key=%s&info=%s"%(appkey,info)
	req=requests.get(url)
	content=req.text
	data=json.loads(content)
	answer=data['text']
	return answer


def tuling(info):
	appkey="e5ccc9c7c8834ec3b08940e290ff1559"
	url="http://www.tuling123.com/openapi/api?key=%s&info=%s"%(appkey,info)
	req=requests.get(url)
	content=req.text
	data=json.loads(content)
	answer=data['text']
	return answer

	

def group_id(name):
	df=itchat.search_chatrooms(name=name)
	#print(df)
	return df[0]['UserName']
	

@itchat.msg_register(TEXT, isGroupChat=True)
def group_text_reply(msg):
	#print(msg['Text'])
	#print(msg)
	item=group_id(u'功德屌丝群')  
	#print(item)
	if msg['FromUserName']==item:
		itchat.send(u'%s' %tuling(msg['Text']),item)
	
itchat.auto_login()
itchat.run()